import os
import utils
import imagesize
from tqdm import tqdm


SrcDir = r"/media/fang/TOSHIBA EXT/Temp/720*360/LD"
# SrcLabelName = ['RemoveLimit-100', 'RemoveLimit-110', 'RemoveLimit-120', 'RemoveLimit-130', 'RemoveLimit-50', 'RemoveLimit-60', 'RemoveLimit-70', 'RemoveLimit-80', 'RemoveLimit-90', 'RemoveLimit110', 'RemoveLimit120', 'RemoveLimit130', 'RemoveLimit20', 'RemoveLimit30', 'RemoveLimit40', 'RemoveLimit50', 'RemoveLimit60', 'RemoveLimit70', 'RemoveLimit80', 'Removelimit-100', 'Removelimit-120', 'Removelimit-130', 'Removelimit-50', 'Removelimit-60', 'Removelimit-80', 'Removelimit-90']
# DstLabelName = 'RemoveLimit'
# SrcLabelName = ['100', '105', '110', '115', '120', '130', '15', '20', '25', '30', '35', '40', '40 ', '45', '50', '55', '60', '65', '70', '75', '80', '85', '90', '95']
# DstLabelName = 'Limit'
# SrcLabelName = ['RemoveLimit']
# DstLabelName = 'UnLimit'
SrcLabelName = ['Limit']
DstLabelName = 'AmericaLimit'
# night45	: 340
# night65	: 2

ReWriteKey = False

for root, dirs, files in os.walk(SrcDir):
    for file in tqdm(files):
        if file[-1] == 'l':
            Infos = utils.ReadXml(root + "/" + file)
            NewInfos = [root + "/" + file]
            for Info in Infos:
                if Info[-1] in SrcLabelName:
                    ReWriteKey = True
                    Info[-1] = DstLabelName
                NewInfos.append(Info)
            if ReWriteKey:
                ReWriteKey = False
                W, H = imagesize.get(root + "/" + file[:-3] + "jpg")
                utils.WriteXml(NewInfos, W, H)
